package com.bdqn.zhao.controller;


import com.bdqn.zhao.pojo.IpBuilding;
import com.bdqn.zhao.service.IpBuildingService;
import com.bdqn.zhao.service.IpFloorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.Map;

/**
 * <p>
 * 楼宇表 前端控制器
 * </p>
 *
 * @author zhangsan
 * @since 2023-04-24
 */
@Controller
@RequestMapping("/ipBuilding")
public class IpBuildingController {

    @Autowired
    private IpBuildingService ipBuildingService;
    @Autowired
    private IpFloorService ipFloorService;


    // 楼宇列表 --单条件查询 --上下页分页
    @ResponseBody
    @GetMapping("/selectOne/{index}/{count}")
    public Map<String, Object> selectOne(@PathVariable int index,
                                         @PathVariable int count,
                                         @RequestParam(required = false) String buildName) {
        return ipBuildingService.selectOneipBuild(index, count, buildName);
    }


    // 楼宇列表 -- 新增楼宇
    @ResponseBody
    @PostMapping("/save/{parkId}")
    public Boolean ipBuildingsave(@PathVariable int parkId,IpBuilding ipBuilding, HttpSession session) {
        return ipBuildingService.ipBuildingsave(parkId,ipBuilding,session);
    }


    // 楼宇列表 -- 修改楼宇信息
    @ResponseBody
    @PostMapping("/update/{buildId}")
    public Map<String,Object> updates(@PathVariable int buildId, IpBuilding ipBuilding,HttpSession session) {
        return ipBuildingService.updates(buildId, ipBuilding, session);
    }

    // 楼宇列表 -- 删除楼宇信息
    @ResponseBody
    @GetMapping("/delete/{buildId}")
    public Boolean deleteIpBuilding(@PathVariable int buildId) {
        // 先删除楼宇下面所有的楼层信息
        ipFloorService.deletefloors(buildId);
        return ipBuildingService.deleteIpBuilding(buildId);
    }


    // 跳转-----------------------------------------------------

    // 楼宇列表 全查
    @GetMapping("/selectAll")
    public String selectAll(HttpSession session) {
        ipBuildingService.selectAllipBuilding(session);
        return "/ipBuilding";
    }

    // 楼宇列表 -- 跳转修改楼宇  并查询出信息
    @ResponseBody
    @GetMapping("/update/{buildId}")
    public String update(@PathVariable int buildId, HttpSession session) {
        return ipBuildingService.updates(buildId, session);
    }





}

